/**
 * 访问明细
 *
 * @format
 */

import { initBaseDao } from '../sdk'
import { getToday } from '../utils'
import { TEMPLATE_CONFIG_DB_NAME } from '../db'

export default class TemplateService {
  context: IContext<IParams>
  templatedao: IBaseDao
  constructor(context: IContext<IParams>) {
    this.context = context
    this.templatedao = initBaseDao(context, TEMPLATE_CONFIG_DB_NAME)
  }
  /**
   * 增加访问记录
   * @param {模版信息} isFollow
   */
  async addTemplate(userInfo: IUserInfo, templateInfo: ICommonTemplateInfo) {
    const { openId, data } = this.context

    const today = getToday()
    const resultId = await this.templatedao.insertOne({
      ...templateInfo,
      accessTime: Date.now(),
      createTime: Date.now(),
      updateTime: Date.now(),
      createDay: today
    })
    return { id: resultId }
  }
  async getTemplateList() {
    const { activityId, filed = '' } = this.context?.data || this.context

    const res = await this.templatedao.find({ activityId })

    return res;
  }
}
